import { minCache } from '@/utils/min-cache'
//#ifdef H5
import MobileDetect from 'mobile-detect'
const md = new MobileDetect(window.navigator.userAgent)
//#endif

const systemInfo: any = uni.getSystemInfoSync()

export default function () {
  const netType = minCache.get('networkType')
  const position = minCache.get('position')
  const loginAddress = position ? position.provinceName + position.cityName + position.regionName : ''

  let deviceInfo = JSON.stringify({
    OS: systemInfo.system,
    brand: systemInfo.brand,
    model: systemInfo.model,
    netType,
    loginAddress,
  })

  //#ifdef H5
  deviceInfo = JSON.stringify({
    OS: md.os(), // 操作系统
    Brand: md.phone(), // 设备品牌
    model: md.mobile(), // 设备型号
    netType, // 登陆网络类型
    loginAddress, // 登陆地址
  })
  //#endif

  return deviceInfo
}
